package com.savitar.menu.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.savitar.menu.entity.Menu;
import com.savitar.menu.entity.MenuVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (Menu)数据库访问层
 *
 * @author Savitar
 * @since 2021-05-16 09:28:25
 */
@Mapper
public interface MenuMapper extends BaseMapper<Menu> {

    @Select("select * from t_menu where pid = #{pid} order by order_num asc")
    List<MenuVo> listByPid(String pid);

    @Select("select * from t_menu where level = #{level} order by order_num asc")
    List<MenuVo> listByLevel(Integer level);

    List<MenuVo> listByLevelAndRole(@Param("level") Integer level, @Param("roleId") String roleId);

    List<MenuVo> listByPidAndRole(@Param("pid") String pid,@Param("roleId") String roleId);

    List<String> listMenuIdByRole(String roleId);

    int createRole2Menu(@Param("roleId")String roleId,@Param("menus") List<String> menus);

    int deleteByRole(String roleId);
}